﻿@model Beginner.Blog.Core.PagedList<Beginner.Blog.Models.Log>
@{
    ViewBag.Title = "系统日志";
    Layout = "~/Views/Shared/_ManageLayoutPage.cshtml";
}
<blockquote class="layui-elem-quote">
    系统日志
</blockquote>

<div class="blog-manage-table table-responsive">
    <table class="table table-hover table-striped table-bordered">
        <thead>
            <tr>
                <th>ID</th>
                <th>线程ID</th>
                <th>日志等级</th>
                <th>日志名称</th>
                <th>日志时间</th>
                <th>日志信息</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody>
            @if (Model.Items != null && Model.Items.Count > 0)
            {
                foreach (var item in Model.Items)
                {
                    <tr>
                        <td>@item.Id</td>
                        <td>@item.Thread</td>
                        <td>@item.Level</td>
                        <td>@item.Logger</td>
                        <td>@item.Date</td>
                        <td>@item.Message</td>
                        <td>
                            <a href="javascript:;" data-id="@item.Id" data-opt="detail">详情</a>
                        </td>
                    </tr>
                }
            }
            else
            {
                <tr>
                    <td colspan="7" style="text-align:center;">暂无数据</td>
                </tr>
            }
        </tbody>
    </table>
    <div class="blog-manage-page">
        <div id="page" style="padding-left:20px;"></div>
    </div>
</div>
<style>
    .log-detail-box {padding: 15px;}
    .log-detail-box-main {position: relative;padding: 10px 0;}
    .log-detail-box-main label {position: absolute;}
    .log-detail-box-main p {margin-left: 70px;}
</style>
<script type="text/html" id="detail-temp">
    <div class="log-detail-box">
        <div class="log-detail-box-main">
            <label>线程ID:</label>
            <p>{{ d.data.Thread }}</p>
        </div>
        <div class="log-detail-box-main">
            <label>日志等级:</label>
            <p>{{ d.data.Level }}</p>
        </div>
        <div class="log-detail-box-main">
            <label>日志名称:</label>
            <p>{{ d.data.Logger }}</p>
        </div>
        <div class="log-detail-box-main">
            <label>日志时间:</label>
            <p>{{ d.data.Date }}</p>
        </div>
        <div class="log-detail-box-main">
            <label>日志信息:</label>
            <p>{{ d.data.Message }}</p>
        </div>
        <div class="log-detail-box-main">
            <label>异常信息:</label>
            <p>{{ d.data.Exception }}</p>
        </div>
    </div>
</script>
@section scripts{
    <script>
        layui.use(['laypage', 'layer','laytpl'], function () {
            var laypage = layui.laypage
            ,$ = layui.jquery
            ,layer = layui.layer
            ,laytpl = layui.laytpl;;
            //laypage
            laypage({
                cont: 'page'
                ,curr:@Model.CurrentPage
                , pages: @Model.TotalPages //总页数
                , groups: 5 //连续显示分页数
                ,jump:function(obj, first){
                    //得到了当前页，用于向服务端请求对应数据
                    var curr = obj.curr;
                    if(!first){
                        //layer.msg('第 '+ obj.curr +' 页');
                        location.href = '/manage/log_list_'+curr+'_'+@Model.ItemsPerPage;
                    }
                }
            });
            //绑定详情事件
            $('a[data-opt=detail]').each(function(){
                $(this).on('click',function(){
                    var $this =$(this);
                    var id = $this.data('id');
                    $.getJSON('@Url.Action("Detail", "Log")',{id:id},function(result){

                        var getTpl = $('#detail-temp').html();
                        laytpl(getTpl).render(result, function(html){
                            if(result.success){
                                layer.open({
                                    title:'日志详情',
                                    type: 1,
                                    skin: 'layui-layer-rim', //加上边框
                                    area: ['800px', '600px'], //宽高
                                    content: html
                                });
                            }
                        });
                    });
                });
            });

            var $item = $('.layui-nav > .layui-nav-item');
            $item.removeClass('layui-this').eq(4).addClass('layui-this');

        });
    </script>
}